/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProfilBilgisiGoster.java
 *
 * Created on 28.Ara.2011, 17:47:55
 */
package oopdesignpatternsproject;

import factories.ListStrategyFactory;
import strategies.IListStrategy;
import entityclasses.Session;
import java.awt.Component;
import java.awt.Panel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import entityclasses.LinkTextShare;
import entityclasses.PlainTextShare;
import entityclasses.Share;
import entityclasses.Person;

/**
 *
 * @author YCAN
 */
public class ProfilBilgisiGoster extends javax.swing.JFrame {

    /** Creates new form ProfilBilgisiGoster */
    Person currentPerson;
    int konum;
    public ProfilBilgisiGoster(Person p,int konum) {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.konum = konum;
        
        if(konum == 0)
            btnEkle.setVisible(false);
        else btnEkle.setVisible(true);
        
        currentPerson = p;
        
        
        this.setup();
    }
    public ProfilBilgisiGoster() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    public void setup()
    {
        lblProfil.setText(currentPerson.getProfile().getProfileName());
        lblAd.setText(currentPerson.getFirstName());
        lblSoyad.setText(currentPerson.getLastName());
        lblIliski.setText(currentPerson.getProfile().getRelationship().toString());
        lblArkadasSay.setText(currentPerson.getProfile().getFriends().size()+"");
        getSharedStatuses();
        listAkrabalar.setModel(ListStrategyFactory.createStrategy(IListStrategy.Related).list());
        
        
    }
    
    public void getSharedStatuses()
    {
        pnlPaylasimlar.removeAll();
        
        for(Share s : currentPerson.getProfile().getShares())
        {
            shareInReal(s);
        }
    }
    
public void shareInReal(Share newShare)
    {   
        JLabel paylasim = new JLabel();
        if(newShare.getShareStrategy() instanceof PlainTextShare)
        {
        paylasim.setText(newShare.getContent());
        }
        else 
        {
            paylasim.setText("<html><font color=\"#0000CF\"><u>"+newShare.getContent()+"</u></font></html>");
        }
        paylasim.setSize(400,60);
        paylasim.setVisible(true);
        kaydir();
        pnlPaylasimlar.add(paylasim);
    }

public void kaydir()
{
    int sayac = 0;
    for(Component c : pnlPaylasimlar.getComponents())
    {
        sayac += 60;
        c.setLocation(c.WIDTH,c.HEIGHT+sayac);
    }
}
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblProfil = new javax.swing.JLabel();
        lblAd = new javax.swing.JLabel();
        lblSoyad = new javax.swing.JLabel();
        lblArkadasSay = new javax.swing.JLabel();
        lblIliski = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        pnlPaylasimlar = new javax.swing.JPanel();
        btnEkle = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listAkrabalar = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Profil Adı");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel2.setText("Ad");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setText("Soyad");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Arkadaş Sayısı");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("İlişki Durumu");
        jLabel5.setName("jLabel5"); // NOI18N

        lblProfil.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblProfil.setText("Value");
        lblProfil.setName("lblProfil"); // NOI18N

        lblAd.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblAd.setText("Value");
        lblAd.setName("lblAd"); // NOI18N

        lblSoyad.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblSoyad.setText("Value");
        lblSoyad.setName("lblSoyad"); // NOI18N

        lblArkadasSay.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblArkadasSay.setText("Value");
        lblArkadasSay.setName("lblArkadasSay"); // NOI18N

        lblIliski.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblIliski.setText("Value");
        lblIliski.setName("lblIliski"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel6.setText("Paylaşımlar");
        jLabel6.setName("jLabel6"); // NOI18N

        pnlPaylasimlar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlPaylasimlar.setName("pnlPaylasimlar"); // NOI18N

        javax.swing.GroupLayout pnlPaylasimlarLayout = new javax.swing.GroupLayout(pnlPaylasimlar);
        pnlPaylasimlar.setLayout(pnlPaylasimlarLayout);
        pnlPaylasimlarLayout.setHorizontalGroup(
            pnlPaylasimlarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 443, Short.MAX_VALUE)
        );
        pnlPaylasimlarLayout.setVerticalGroup(
            pnlPaylasimlarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 231, Short.MAX_VALUE)
        );

        btnEkle.setText("Arkadaşlık İsteği Gönder");
        btnEkle.setName("btnEkle"); // NOI18N
        btnEkle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnEkleMouseClicked(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel8.setText("Akrabalar");
        jLabel8.setName("jLabel8"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        listAkrabalar.setName("listAkrabalar"); // NOI18N
        jScrollPane1.setViewportView(listAkrabalar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
                        .addContainerGap())
                    .addComponent(pnlPaylasimlar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 190, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblIliski)
                            .addComponent(lblArkadasSay)
                            .addComponent(lblSoyad)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(lblProfil)
                                .addComponent(lblAd))
                            .addComponent(btnEkle))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addContainerGap(381, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblProfil)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblAd, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblSoyad)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblArkadasSay)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblIliski)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(btnEkle))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlPaylasimlar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnEkleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnEkleMouseClicked
    Session.currentUser.addAsFriend(currentPerson);
}//GEN-LAST:event_btnEkleMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ProfilBilgisiGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ProfilBilgisiGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ProfilBilgisiGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ProfilBilgisiGoster.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ProfilBilgisiGoster().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEkle;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAd;
    private javax.swing.JLabel lblArkadasSay;
    private javax.swing.JLabel lblIliski;
    private javax.swing.JLabel lblProfil;
    private javax.swing.JLabel lblSoyad;
    private javax.swing.JList listAkrabalar;
    private javax.swing.JPanel pnlPaylasimlar;
    // End of variables declaration//GEN-END:variables
}
